package com.example.filesaveqq;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.TextureView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.Map;

public class Main2Activity extends AppCompatActivity implements View.OnClickListener {
    private EditText et_account,et_password;
    private Button btn_login;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        Map<String,String> userInfo=SPSaveQQ.getUserInfo(this);
        if(userInfo!=null){
            et_account.setText(userInfo.get("account"));
            et_password.setText(userInfo.get("password"));
        }
    }

    private void initView() {
        et_account=(EditText) findViewById(R.id.et_account);
        et_password=(EditText) findViewById(R.id.et_password);
        btn_login=(Button) findViewById(R.id.btn_login);
        btn_login.setOnClickListener(this);
        Toast.makeText(this,"this is "+this.toString(),Toast.LENGTH_LONG).show();
    }

    @Override
    public void onClick(View view) {
        switch(view.getId()){
            case R.id.btn_login:
                String account=et_account.getText().toString().trim();
                String password=et_password.getText().toString().trim();
                if(TextUtils.isEmpty(account)){
                    Toast.makeText(this,"请输入QQ账号", Toast.LENGTH_LONG).show();
                    return;
                }
                if(TextUtils.isEmpty(password)){
                    Toast.makeText(this,"请输入密码",Toast.LENGTH_LONG).show();
                    return;
                }
                Toast.makeText(this,"登录成功！", Toast.LENGTH_LONG).show();
                boolean isSaveSuccess =SPSaveQQ.saveUserInfo(this,account,password);
                if(isSaveSuccess){
                    Toast.makeText(this,"保存成功！", Toast.LENGTH_LONG).show();
                }else{
                    Toast.makeText(this,"保存失败！",Toast.LENGTH_LONG).show();
                }
                break;
        }
    }
}
